package com.example.demo01;

import java.io.*;
import java.util.ArrayList;
import java.util.List;

/**
 * description: JPasswordFieldDemo <br>
 * date: 2020/12/30 10:29 <br>
 *
 * @author: ZhangYixin <br>
 * version: 1.0 <br>
 */
public class JPasswordFieldDemo {
    public static void main(String[] args) {
        // 找出目录下的所有子目录以及子文件并打印到控制台
        List<String> paths = new ArrayList<>();

        getAllFilePaths(new File("C:/Users/user/Desktop/data"),paths);

        for (String path : paths){
            System.out.println(path);
        }
    }

    public static void test(){
        try (
                FileInputStream fis = new FileInputStream("C:/Users/user/Desktop/data/ioTest.txt");
                BufferedInputStream bufferedInputStream = new BufferedInputStream(fis);
                FileOutputStream fos = new FileOutputStream("C:/Users/user/Desktop/data/ioTest_copy.txt");
                BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(fos);
                ){
            int size ;
            byte[] buf = new byte[32];
            while (((size = bufferedInputStream.read(buf)) != -1)) {
                System.out.println(new String(buf));
                bufferedOutputStream.write(buf,0,size);
            }

        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    public static void getAllFilePaths(File filePath, List<String> paths){
        File[] files = filePath.listFiles();
        if (files == null){
            return;
        }
        for (File fl : files){
            // isDirectory()是检查一个对象是否是文件夹。返回值是boolean类型的。如果是则返回true，否则返回false。
            if (fl.isDirectory()){
                paths.add(fl.getPath());
                getAllFilePaths(fl,paths);
            }else {
                paths.add(fl.getPath());
            }
        }
    }
}

